/*
 */

package com.railway.system.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import cn.org.rapid_framework.page.Page;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.railway.common.base.BaseStruts2Action;
import com.railway.common.constants.SysConstant;
import com.railway.common.util.EasyUIJsonUtil;
import com.railway.common.util.Json;
import com.railway.common.util.StaticMethod;
import com.railway.news.model.Category;
import com.railway.news.model.CategoryUserLink;
import com.railway.news.service.ICategoryManager;
import com.railway.news.vo.query.CategoryQuery;
import com.railway.system.model.SysDept;
import com.railway.system.model.SysFrel;
import com.railway.system.model.SysFunc;
import com.railway.system.model.SysUser;
import com.railway.system.service.ISysDeptManager;
import com.railway.system.service.ISysFrelManager;
import com.railway.system.service.ISysFuncManager;
import com.railway.system.service.ISysUserManager;
import com.railway.system.vo.query.SysFrelQuery;
import com.railway.system.vo.query.SysFuncQuery;
import com.railway.system.vo.query.SysUserQuery;

/**
 * @author jiangcheng
 * @version 1.0
 * @since 1.0
 */

public class SysUserAction extends BaseStruts2Action implements Preparable,
		ModelDriven {
	// 默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null;

	private ISysDeptManager sysDeptManager;
	// forward paths
	protected static final String QUERY_JSP = "/admin/system/sysUser/query.jsp";
	// modified by user01
	protected static final String LIST_JSP = "/admin/system/sysUser/list.jsp";
	protected static final String CREATE_JSP = "/admin/system/sysUser/create.jsp";
	protected static final String EDIT_JSP = "/admin/system/sysUser/edit.jsp";
	protected static final String SHOW_JSP = "/admin/system/sysUser/show.jsp";

	protected static final String LOG_OUT = "/admin/index.jsp";
	protected static final String MSG_OUT = "/index.jsp";

	protected static final String MAIN_FRAME_JSP = "/admin/frame.jsp";
	protected static final String MSG_FRAME_JSP = "/msg/frame.jsp";
	protected static final String LIST_ACTION = "!/system/SysUser/list.do";

	private ISysUserManager sysUserManager;
	private ISysFuncManager sysFuncManager;
	private ICategoryManager categoryManager; 
	private ISysFrelManager sysFrelManager;
	// 获取登录的用户名
	public String userName;
	// 获取输入的密码
	public String userPwd;

	private SysUser sysUser;
	java.lang.String id = null;
	private String[] items;
	private String param;

	public void setSysDeptManager(ISysDeptManager sysDeptManager) {
		this.sysDeptManager = sysDeptManager;
	}
	public String savechagedpwd() {

		String pwd1 = this.getRequest().getParameter("pass_word");
		String pwd2 = this.getRequest().getParameter("pass_word1");
		if (pwd1 != null) {
			if (pwd1.equals(pwd2)) {
				String current_user_id = (String) this.getRequest()
						.getSession().getAttribute(SysConstant.USER_ID);
				SysUser u = sysUserManager.getById(current_user_id);
				u.setUserPwd(pwd1);
				sysUserManager.update(u);
				this.getRequest().getSession().setAttribute("password", pwd1);
			}
		}
		return null;
	}
	public String getUserDeptTree() {

		List list = new ArrayList();
		List<SysDept> deptList = sysDeptManager.findAll();

		if (deptList != null) {
			for (int i = 0; i < deptList.size(); i++) {

				SysDept sd = (SysDept) deptList.get(i);
				// {id:1, pId:0, name:"部门01", open:true, nocheck:false,type:0},
				Map map = new HashMap();

				map.put("id", "D" + sd.getId());
				map.put("pId", sd.getParentDeptid());
				map.put("name", sd.getDeptName());
				map.put("open", "true");
				map.put("type", "0");
				
				list.add(map);

			}
		}
		return writeAjaxResponse(Json.toJson(list));

	}

	public String showUserList() {
		return "/admin/system/sysUser/userlist.jsp";
	}

	/**
	 * 以列表形式显示部门人员对话框
	 * 
	 * @return
	 */
	public String showDeptUserList() {
		return "/admin/system/sysUser/deptuserlist.jsp";
	}
   public String getAjaxOnlineUsers(){
	   
		
		// 获得在线用户
		ServletContext application = this.getRequest().getSession().getServletContext();
		Set sessions = (HashSet) application.getAttribute(SysConstant.USER_SESSIONS);
        StringBuffer resultsb = new StringBuffer();

		resultsb.append("[");
		int i = 0 ;
		if (sessions != null) {
			for (Iterator it = sessions.iterator(); it.hasNext();) {				
				HttpSession sess = (HttpSession) it.next();
				if(i > 0){
					
					resultsb.append(",");
				}
					resultsb.append("{uid:\"");
					resultsb.append((String) sess.getAttribute(SysConstant.USER_ID));
					resultsb.append("\"}");
				i++;
			}
		}
		resultsb.append("]");
		
		return writeAjaxResponse(resultsb.toString());
	   
   }
	/**
	 * 获得表格形式的用户部门信息 说明： un代表用户名 uid代表部门Id un,did以此类推
	 * 
	 * @return
	 */
	public String getUserDeptList() {
		
		String calltypes = this.getRequest().getParameter(SysConstant.USER_CALL_TYPES);
		
		
		// 获得在线用户
		ServletContext application = this.getRequest().getSession().getServletContext();
		Set sessions = (HashSet) application.getAttribute(SysConstant.USER_SESSIONS);
		Map umap = new HashMap();
		if (sessions != null) {
			for (Iterator it = sessions.iterator(); it.hasNext();) {				
				HttpSession sess = (HttpSession) it.next();
				umap.put((String) sess.getAttribute(SysConstant.USER_ID), "");
			}
		}

		StringBuffer resultsb = new StringBuffer();
		
		resultsb.append("[");
		// 获得所有部门
		
		List<SysDept> deptList = sysDeptManager.findAll();
		
		if (deptList != null) {
			
			SysDept temp_sd = new SysDept();
			temp_sd.setId("EMPTY");//部门为空的情况
			temp_sd.setDeptName("");
			
			deptList.add(temp_sd);

			for (int i = 0; i < deptList.size(); i++) {
			
				SysDept sd = (SysDept) deptList.get(i);
 
				if (i > 0) {
					resultsb.append(",");
				}
				resultsb.append("{dn:\"").append(sd.getDeptName()).append("\",did:\"").append(
						sd.getId() == "" ? System.currentTimeMillis() + i : sd
								.getId());
				resultsb.append("\",users:[");

				// 根据部门获得相应的用户列表
				SysUserQuery query = newQuery(SysUserQuery.class,DEFAULT_SORT_COLUMNS);				
				query.setDeptId(sd.getId());
				
 		//		if(sd.getId() != null && !"".equals(sd.getId())) {
				
 				 
				    query.setSortColumns("USER_NO");
				    
				    List userList = sysUserManager.getUsers(query);

				    if (userList != null) {
				    	for (int k = 0; k < userList.size(); k++) {

				    		SysUser su = (SysUser) userList.get(k);
				    		//
				    		//判断一下,如果是消息呼叫用户列表则不显示虚拟用户
				    		
						// 如果是部门虚拟用户,则退出
				    		if(SysConstant.USER_CALL_TYPES_MSG.equals(calltypes)){
				    		  if ((SysConstant.ID_TYPE_DEPT).equals(su.getCardType())){
				    			continue;
				    		  }
				    		}
				    		if (k > 0) {
				    			resultsb.append(",");
				    		}

						StringBuffer b = new StringBuffer();
						b.append("姓名:").append(
								StaticMethod.null2String(su.getUserName()));
						b
								.append("<br>职务:")
								.append(
										StaticMethod.null2String(su
												.getPosition()))
								.append("<br>电话:")
								.append(StaticMethod.null2String(su.getPhone()))
								.append("<br>手机:").append(
										StaticMethod
												.null2String(su.getMobile()));

						resultsb.append("{un:\"").append(su.getUserName())
						.append("\",uid:\"").append(su.getId()).append(
								"\",uinfo:\"").append(b.toString())
						.append("\",ustatus:\"").append(
								umap.get(su.getId()) == null ? "black"
										: "blue").append("\"}");
						

					}
				}
		//	}
				resultsb.append("]}");

			}

		}
	

		// 处理没有部门的人员,这里留个口，如果有不属于任何部门的人则在这里添加 --开始

		// 处理没有部门的人员,这里留个口，如果有不属于任何部门的人则在这里添加--结束
		resultsb.append("]");
		//System.out.println(resultsb);
		return writeAjaxResponse(resultsb.toString());

	}

	public String getUserDept() {

		List list = new ArrayList();
		List<SysDept> deptList = sysDeptManager.findAll();

		if (deptList != null) {
			for (int i = 0; i < deptList.size(); i++) {

				SysDept sd = (SysDept) deptList.get(i);
				// {id:1, pId:0, name:"部门01", open:true, nocheck:false,type:0},
				Map map = new HashMap();

				map.put("id", "D" + sd.getId());
				map.put("icon", "../../css/dept.gif");
				map.put("pId", sd.getParentDeptid());
				map.put("name", sd.getDeptName());
				map.put("open", "true");

				map.put("type", "0");
				list.add(map);

			}

		}

		List<SysUser> userList = sysUserManager.findAll();
		if (userList != null) {
			for (int k = 0; k < userList.size(); k++) {
				SysUser su = (SysUser) userList.get(k);
				Map map = new HashMap();
				map.put("id", "U" + su.getId());
				map.put("icon", "../../css/user.gif");
				map.put("pId", "D" + su.getDeptId());
				map.put("userid", su.getUserId());
				map.put("name", su.getUserName());
				map.put("open", "true");
				map.put("type", "1");
				list.add(map);
			}
		}
		return writeAjaxResponse(Json.toJson(list));

	}

	public void setParam(String param) {
		this.param = param;
	}

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			sysUser = new SysUser();
		} else {
			sysUser = (SysUser) sysUserManager.getById(id);
			//这里对部门名称处理一下
			if(sysUser != null){
			SysDept sd =   sysDeptManager.getById(sysUser.getDeptId());
			sysUser.setDeptName(sd.getDeptName());
			}
		}
	}

	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setSysUserManager(ISysUserManager manager) {
		this.sysUserManager = manager;
	}

	public Object getModel() {
		return sysUser;
	}

	public void setId(java.lang.String val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}

	/**
	 * user01
	 * 
	 * @return
	 */
	public String login() {

		String userId = "";
		Boolean flag = false;
		String result = "";
		if (!userName.equals("") && !userPwd.equals("")) {

			SysUserQuery queryTwo = newQuery(SysUserQuery.class,
					DEFAULT_SORT_COLUMNS);
			// 设置一个很大的 pagesize

			queryTwo.setUserName(userName);
			queryTwo.setUserPwd(userPwd);
		//	queryTwo.setAreaId("admin");
			Page pageTwo = sysUserManager.findPage(queryTwo);
			List<SysUser> userlist = pageTwo.getResult();
			for (SysUser u : userlist) {
				if ((u.getUserName().equals(userName))
						&& (u.getUserPwd().equals(userPwd))) {
					flag = true;
					userId = u.getId();

					this.getRequest().getSession().setAttribute("userId",
							userId);
					this.getRequest().getSession().setAttribute("username",
							u.getUserName());

					this.getRequest().getSession().setAttribute("password",
							u.getUserPwd());
				}
			}

		}
		System.out.print(this.getRequest().getSession().getAttribute("username")); 
		if (!flag && !(this.getRequest().getSession().getAttribute("username") != null && !getRequest().getSession().getAttribute("username").equals(
						""))) {
			result = "用户名、密码错误";
			this.getRequest().setAttribute("result", result);
			return LOG_OUT;
		}
		return MAIN_FRAME_JSP;
	}

	public String msgLogin() {

		String userId = "";
		Boolean flag = false;
		String result = "";
		if (!userName.equals("") && !userPwd.equals("")) {

			SysUserQuery queryTwo = newQuery(SysUserQuery.class,
					DEFAULT_SORT_COLUMNS);
			// 设置一个很大的 pagesize

			queryTwo.setUserName(userName);
			queryTwo.setUserPwd(userPwd);
			queryTwo.setAreaId("msg");
			Page pageTwo = sysUserManager.findPage(queryTwo);
			List<SysUser> userlist = pageTwo.getResult();
			for (SysUser u : userlist) {
				if ((u.getUserName().equals(userName))
						&& (u.getUserPwd().equals(userPwd))) {
					flag = true;
					userId = u.getId();

					this.getRequest().getSession().setAttribute("userId",
							userId);
					this.getRequest().getSession().setAttribute("username",
							u.getUserName());

					this.getRequest().getSession().setAttribute("password",
							u.getUserPwd());
				}
			}

		}
		if (!flag) {
			result = "用户名、密码错误";
			this.getRequest().setAttribute("result", result);
			return MSG_OUT;
		}
		return MSG_FRAME_JSP;
	}

	public String getDeptUserList() {
		return "";

	}

	public String getFuncList() {

		if (this.getRequest().getSession().getAttribute("userId") != null
				&& !this.getRequest().getSession().getAttribute("userId")
						.equals("")) {
			String userId = this.getRequest().getSession().getAttribute(
					"userId").toString();
			List<SysFunc> userFuncList = new ArrayList();

			if (this.getRequest().getSession().getAttribute("username") != null) {
				userName = this.getRequest().getSession().getAttribute(
						"username").toString();

			}
			if (userName.equals("admin")) {
				SysFuncQuery query = newQuery(SysFuncQuery.class,
						DEFAULT_SORT_COLUMNS);
				userFuncList = sysFuncManager.getUserFunc(query);

			} else {
				
				//添加所属栏目
				CategoryUserLink culinkquery=new CategoryUserLink();
				culinkquery.setUserid(userId);
				culinkquery.setState("M");//M代表维护
				List<CategoryUserLink> userCate=categoryManager.getPermitCategoriesByUser(culinkquery);
			 
				StringBuffer userCates=new StringBuffer("");
				if(userCate!=null){
					for(int i=0;i<userCate.size();i++){
						CategoryUserLink categoryUserLink=userCate.get(i);
						userCates.append(categoryUserLink.getCategoryid()+",");
					}
				}
			   this.getRequest().getSession().setAttribute("userCates",  userCates); 
			    userFuncList= sysFuncManager.getUserFunc(userId);
			  
				
			}

			List<Map> treedataList = new ArrayList<Map>();

			for (SysFunc t : userFuncList) {
				Map<String, Object> map = new HashMap();
				map.put("id", t.getId());
				map.put("parentId", t.getParentId());
				map.put("order", 1);
				map.put("text", t.getFuncName());
				map.put("iconCls", "icon-dept");

				Map amap = new HashMap();
				// 权限url
				amap.put("url", t.getFuncUrl());
				map.put("attributes", amap);
				treedataList.add(map);
			}

			Map<String, Object> root = new HashMap();
			root.put("id", "-1");
			root.put("text", "操作列表");
			root.put("iconCls", "icon-ok");
			root.put("url", "#");
			// 增加顶级节点的deptcode。。以便页面上生成顶级节点的子部门时出错
			Map amap = new HashMap();
			amap.put("deptCode", "");
			root.put("attributes", amap);
			String jsonStr = EasyUIJsonUtil.createTreeJsonString(root,
					treedataList);
			return writeAjaxResponse(jsonStr);
		} else {
			return "";
		}
	}

	public String logout() {
		this.getRequest().getSession().setAttribute("userId", null);
		this.getRequest().getSession().setAttribute("username", null);
		this.getRequest().getSession().setAttribute("password", null);
		this.getRequest().getSession().invalidate();//主动使session失效
		if (param != null&&param.equals("msg")) {
			return MSG_OUT;
		}
		return LOG_OUT;
	}

	/** 执行搜索 */
	public String list() {

		return LIST_JSP;
	}

	public String listAjax() {

		SysUserQuery query = newQuery(SysUserQuery.class, DEFAULT_SORT_COLUMNS);

		System.out.print(sysUserManager);
		Page page = sysUserManager.findPage(query);
		Map map = new HashMap();
		map.put("total", page.getTotalCount());
		map.put("rows", page.getResult());
		return writeAjaxResponse(Json.toJson(map));
	}

	/** 查看对象 */
	public String show() {
		return SHOW_JSP;
	}

	/** 进入新增页面 */
	public String create() {
		
		Map mapCat = new HashMap();
		List<Category> listCat = categoryManager.findAll();
		if (listCat != null) {
			for (int i = 0; i < listCat.size(); i++) {
				Category cate = listCat.get(i);
				if (cate.getPublicType() != null) {
					List<Category> temp=new ArrayList();
					if (mapCat.get(cate.getPublicType()) != null) {
						temp=(List)mapCat.get(cate.getPublicType());
					} 
					temp.add(cate);
					mapCat.put(cate.getPublicType(), temp);
				}
				
			}
		}
		
		SysFuncQuery query = newQuery(SysFuncQuery.class, DEFAULT_SORT_COLUMNS);
		query.setSortColumns("FUNC_CODE");
		List<SysFunc> listFunc = sysFuncManager.getUserFunc(query);
		List<SysFunc> resultList=new ArrayList();
		if(listFunc!=null){
			for(int i=0;i<listFunc.size();i++){
				SysFunc sysfunc = listFunc.get(i);
				String url=sysfunc.getFuncUrl();
				if(url!=null&&url.indexOf("/news/News/getNewsByTitle.do?title=")>-1){
					String key=url.replace("/news/News/getNewsByTitle.do?title=", "");
					if(mapCat.get(key)!=null){
						sysfunc.setCateList((List)mapCat.get(key));
					}
				}
				resultList.add(sysfunc);
			}
		} 
		this.getRequest().setAttribute("sysfunc", resultList);
		return CREATE_JSP;
	}

	/** 保存新增对象 */
	public String save() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		// 添加访问区域
		String[] area = this.getRequest().getParameterValues("area");
		StringBuffer temp = new StringBuffer();
		if (area != null) {
			for (int i = 0; i < area.length; i++) {
				temp.append(area[i] + ",");
			}
		}
		sysUser.setAreaId(temp.toString());
		sysUser.setCreateTime(new Date());
		sysUser.setCreateTimeString(sdf.format(new Date()));
		sysUser.setCreator((String) this.getRequest().getSession()
				.getAttribute("userId"));
		String userId=sysUserManager.saveUser(sysUser);
		
		// 添加权限
		String[] funcs = this.getRequest().getParameterValues("funcs");
		if(funcs!=null){
			for(int i=0;i<funcs.length;i++){
				SysFrel sysFrel=new SysFrel();
				sysFrel.setFuncId(funcs[i]);
				sysFrel.setRoleId(userId);
				sysFrelManager.save(sysFrel);
			}
		}
		// 添加栏目
		String[] cates = this.getRequest().getParameterValues("cates");
		if(cates!=null){
			for(int i=0;i<cates.length;i++){
				CategoryUserLink categoryUserLink=new CategoryUserLink();
				categoryUserLink.setCategoryid(cates[i]);
				categoryUserLink.setUserid(userId);
				categoryUserLink.setState("M");
				categoryManager.saveCategoryUserLink(categoryUserLink);
			}
		}
		//添加所有栏目访问权限。
		List list=categoryManager.findAll();
		if(list!=null){
			for(int i=0;i<list.size();i++){
				Category category=(Category)list.get(i);
				if(!category.getCaTypes().equals("SOFT")){
					CategoryUserLink categoryUserLink=new CategoryUserLink();
					categoryUserLink.setCategoryid(category.getId());
					categoryUserLink.setUserid(userId);
					categoryUserLink.setState("V");
					categoryManager.saveCategoryUserLink(categoryUserLink);
				}
				
			}
		}
		return LIST_ACTION;
	}

	/** 进入更新页面 */
	public String edit() {
		Map mapCat = new HashMap();
		List<Category> listCat = categoryManager.findAll();
		if (listCat != null) {
			for (int i = 0; i < listCat.size(); i++) {
				Category cate = listCat.get(i);
				if (cate.getPublicType() != null) {
					List<Category> temp=new ArrayList();
					if (mapCat.get(cate.getPublicType()) != null) {
						temp=(List)mapCat.get(cate.getPublicType());
					} 
					temp.add(cate);
					mapCat.put(cate.getPublicType(), temp);
				}
			}
		}
		
		SysFuncQuery query = newQuery(SysFuncQuery.class, DEFAULT_SORT_COLUMNS);
		query.setId("");
		query.setSortColumns("FUNC_CODE");
		List<SysFunc> listFunc = sysFuncManager.getUserFunc(query);
		List<SysFunc> resultList=new ArrayList();
		if(listFunc!=null){
			for(int i=0;i<listFunc.size();i++){
				SysFunc sysfunc = listFunc.get(i);
				String url=sysfunc.getFuncUrl();
				if(url!=null&&url.indexOf("/news/News/getNewsByTitle.do?title=")>-1){
					String key=url.replace("/news/News/getNewsByTitle.do?title=", "");
					if(mapCat.get(key)!=null){
						sysfunc.setCateList((List)mapCat.get(key));
					}
				}
				resultList.add(sysfunc);
			}
		} 
		
		SysFrelQuery queryFrel=newQuery(SysFrelQuery.class, DEFAULT_SORT_COLUMNS);
		queryFrel.setId(null);
		queryFrel.setRoleId(id);
		List<SysFrel> userFunc = sysFrelManager.find(queryFrel);
		CategoryUserLink culinkquery=new CategoryUserLink();
		culinkquery.setState("M");
		culinkquery.setUserid(id);
		List<CategoryUserLink> userCate=categoryManager.getPermitCategoriesByUser(culinkquery);
		
		StringBuffer userFuncs=new StringBuffer("");
		if(userFunc!=null){
			for(int i=0;i<userFunc.size();i++){
				SysFrel sysFrel=userFunc.get(i);
				userFuncs.append(sysFrel.getFuncId()+",");
			}
		}
		
		StringBuffer userCates=new StringBuffer("");
		if(userCate!=null){
			for(int i=0;i<userCate.size();i++){
				CategoryUserLink categoryUserLink=userCate.get(i);
				userCates.append(categoryUserLink.getCategoryid()+",");
			}
		}
		
		this.getRequest().setAttribute("userFuncs", userFuncs);
		this.getRequest().setAttribute("userCates", userCates);
		this.getRequest().setAttribute("sysfunc", resultList);
		return EDIT_JSP;
	}

	/** 保存更新对象 */
	public String update() {
		// 添加访问区域
		String[] area = this.getRequest().getParameterValues("area");
		StringBuffer temp = new StringBuffer();
		if (area != null) {
			for (int i = 0; i < area.length; i++) {
				temp.append(area[i] + ",");
			}
		}
		sysUser.setAreaId(temp.toString());
		sysUserManager.update(this.sysUser);
		
		
		SysFrelQuery queryFrel=newQuery(SysFrelQuery.class, DEFAULT_SORT_COLUMNS);
		queryFrel.setId(null);
		queryFrel.setRoleId(sysUser.getId());
		List<SysFrel> userFunc = sysFrelManager.find(queryFrel);
		if(userFunc!=null){
			for(int i=0;i<userFunc.size();i++){
				SysFrel sysFrel=userFunc.get(i);
				sysFrelManager.removeById(sysFrel.getId()) ;
			}
		}
		//categoryManager.removeLinkByUserId(sysUser.getId());
		CategoryUserLink categoryUserLinkQuery=new CategoryUserLink();
		categoryUserLinkQuery.setId(null);
		categoryUserLinkQuery.setUserid(sysUser.getId());
		categoryUserLinkQuery.setState("M");
		List categoryLinck=categoryManager.getPermitCategoriesByUser(categoryUserLinkQuery);
		if(categoryLinck!=null){
			for(int i=0;i<categoryLinck.size();i++){
				CategoryUserLink cateUserLink=(CategoryUserLink)categoryLinck.get(i);
				categoryManager.deleteCategoryUserLinkById(cateUserLink.getId());
			}
		}
		
		// 添加权限
		String[] funcs = this.getRequest().getParameterValues("funcs");
		if(funcs!=null){
			for(int i=0;i<funcs.length;i++){
				SysFrel sysFrel=new SysFrel();
				sysFrel.setFuncId(funcs[i]);
				sysFrel.setRoleId(sysUser.getId());
				sysFrelManager.save(sysFrel);
			}
		}
		// 添加栏目
		String[] cates = this.getRequest().getParameterValues("cates");
		if(cates!=null){
			for(int i=0;i<cates.length;i++){
				CategoryUserLink categoryUserLink=new CategoryUserLink();
				categoryUserLink.setCategoryid(cates[i]);
				categoryUserLink.setUserid(sysUser.getId());
				categoryUserLink.setState("M");
				categoryManager.saveCategoryUserLink(categoryUserLink);
			}
		}
		return LIST_ACTION;
	}

	/** 删除对象 */
	public String delete() {
		if (items != null)
			for (String ids : items) {
				String[] idArray = ids.split(",");
				for (String id : idArray)
					sysUserManager.removeById(id);
			}
		return LIST_ACTION;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	public void setSysFuncManager(ISysFuncManager sysFuncManager) {
		this.sysFuncManager = sysFuncManager;
	}

	public void setCategoryManager(ICategoryManager categoryManager) {
		this.categoryManager = categoryManager;
	}

	public void setSysFrelManager(ISysFrelManager sysFrelManager) {
		this.sysFrelManager = sysFrelManager;
	}

}
